package com.hyk.learning.provider;

import com.hyk.learning.rateLimit.Impl.TokenBucketRateLimitImpl;
import com.hyk.learning.rateLimit.RateLimit;

import java.util.HashMap;
import java.util.Map;

/**
 * @className: RateLimitProvider
 * @author: hyk199710
 * @description: 对应服务限流器提供接口
 * @date: 2024/9/6 0:03
 */
public class RateLimitProvider {
    private Map<String, RateLimit> rateLimitMap = new HashMap();

    public RateLimit getRateLimit(String serviceName){
        if(!rateLimitMap.containsKey(serviceName)){
            RateLimit rateLimit = new TokenBucketRateLimitImpl(100, 10);
            rateLimitMap.put(serviceName, rateLimit);
            return rateLimit;
        }
        return rateLimitMap.get(serviceName);
    }
}
